/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rultax.blackice.physics;

/**
 *
 * @author scottw
 */
public abstract class Physics<PHYSICS_VEC, SCREEN_VEC> {
    private CoordConverter<PHYSICS_VEC, SCREEN_VEC> coordConverter;
    private VectorConverter<PHYSICS_VEC, SCREEN_VEC> vectorConverter;
    
    public Physics(CoordConverter<PHYSICS_VEC, SCREEN_VEC> coordConverter,
	    VectorConverter<PHYSICS_VEC, SCREEN_VEC> vectorConverter){
	this.coordConverter = coordConverter;
	this.vectorConverter = vectorConverter;
    }
    
    public abstract void step();
    public abstract void createWorld();
    public abstract void setGravity(float x, float y);
    public abstract float scalarScreenToWorld(float val);
    public abstract float scalarWorldToScreen(float val);
    
    public PHYSICS_VEC coordScreenToWorld(SCREEN_VEC coord){
	return coordConverter.screenToWorld(coord);
    }
    
    public SCREEN_VEC coordWorldToScreen(PHYSICS_VEC coord){
	return coordConverter.worldToScreen(coord);
    }
    
    public PHYSICS_VEC vectorScreenToWorld(SCREEN_VEC vector){
	return vectorConverter.screenToWorld(vector);
    }
    
    public SCREEN_VEC vectorWorldToScreen(PHYSICS_VEC vector){
	return vectorConverter.worldToScreen(vector);
    }
    
    protected CoordConverter<PHYSICS_VEC, SCREEN_VEC> getCoordConverter(){
	return coordConverter;
    }

    protected void setCoordConverter(CoordConverter<PHYSICS_VEC, SCREEN_VEC> coordConverter) {
	this.coordConverter = coordConverter;
    }

    protected VectorConverter<PHYSICS_VEC, SCREEN_VEC> getVectorConverter() {
	return vectorConverter;
    }

    protected void setVectorConverter(VectorConverter<PHYSICS_VEC, SCREEN_VEC> vectorConverter) {
	this.vectorConverter = vectorConverter;
    }    
    
    public static float map(float value, float istart, float istop, float ostart, float ostop){
	return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
    }
}